<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>1.画点</title>
	<style>
		canvas {
            background-color: rebeccapurple;
		}
	</style>
</head>
<body>
	<canvas id="gl" style="background-color: rebeccapurple;"></canvas>
	<script type="x-shader/x-vertex" id="vertex">
		
		void main(){
			
            gl_PointSize = 2.0; // 设置点的大小
			gl_Position =vec4(0.0,0.0,0.0,1.0);
		}
	</script>
	
	<script type="x-shader/x-fragment" id="fragment">
		void main(){
			gl_FragColor =vec4(0.0,1.0,1.0,1.0);
		}
	</script>
	<script>
		 /** @type {HTMLCanvasElement} */   
		const canvas=document.getElementById("gl")
		const gl=canvas.getContext("webgl")
		canvas.width=1000
		canvas.height=1000
		//流程 1.创建着色器 编译 链接
		const vertex=document.getElementById("vertex").textContent
		const fragment=document.getElementById("fragment").textContent
		
		const vertexShader=gl.createShader(gl.VERTEX_SHADER)
		const fragmentShader=gl.createShader(gl.FRAGMENT_SHADER)
		gl.shaderSource(vertexShader,vertex)
		gl.shaderSource(fragmentShader,fragment)
		gl.compileShader(vertexShader)
		gl.compileShader(fragmentShader)
		const program=gl.createProgram()
		gl.attachShader(program,vertexShader)
		gl.attachShader(program,fragmentShader)
		gl.linkProgram(program)
		gl.useProgram(program)
		gl.viewport(0,0,1000,1000)
        gl.drawArrays(gl.POINTS, 0, 1);
		//画点
	</script>
</body>
</html>
